import React from "react";
import { useSelector, useDispatch } from "react-redux";

const Child2 = () => {
  // 如果加了模块化，获取数据的时候，中间要加模块的名称
  const name = useSelector((state) => {
    console.log(state);
    return state.name.name;
  });
  const dispatch = useDispatch();

  return (
    <>
      child2
      <div>name: {name}</div>
      <button
        onClick={() => dispatch({ type: "changeName", name: "zhangsan" })}
      >
        btn
      </button>
    </>
  );
};

export default Child2;
